package com.server.pinggu.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.server.common.utils.EasyExcelUtils;
import com.server.common.utils.sign.Base64;
import com.server.pinggu.domain.SenPgy;
import com.server.pinggu.domain.SenUserdata;
import com.server.pinggu.dto.UpdateUserJuWeiDTO;
import com.server.pinggu.excel.PgyDataHandle;
import com.server.pinggu.mapper.SenFormsMapper;
import com.server.pinggu.mapper.SenPgyMapper;
import com.server.pinggu.mapper.SenStreetsMapper;
import com.server.pinggu.service.ISenPgyService;
import com.server.pinggu.service.ISenUserdataService;
import com.server.pinggu.upload.SenPgyExcel;
import com.server.pinggu.upload.SenPgyLevelExcel;
import com.server.pinggu.vo.SenPgyRankStatisticsVo;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ltao
 * @date 2022-10-23
 */

@Service
@Slf4j
public class SenPgyServiceImpl extends ServiceImpl<SenPgyMapper, SenPgy> implements ISenPgyService {

    @Resource
    private SenStreetsMapper senStreetsMapper;

    @Resource
    private SenFormsMapper senFormsMapper;

    @Resource
    private ISenUserdataService iSenUserdataService;

    @Override
    public List<SenPgy> queryList(SenPgy senPgy) {
        LambdaQueryWrapper<SenPgy> lqw = Wrappers.lambdaQuery();
        lqw.select(SenPgy::getId, SenPgy::getXm, SenPgy::getZslx);
        if (StringUtils.isNotBlank(senPgy.getStatus())) {
            lqw.eq(SenPgy::getStatus, senPgy.getStatus());
        }
        if (StringUtils.isNotBlank(senPgy.getZslx())) {
            lqw.eq(SenPgy::getZslx, senPgy.getZslx());
        }
        if (StringUtils.isNotBlank(senPgy.getLeibei())) {
            lqw.eq(SenPgy::getLeibei, senPgy.getLeibei());
        }
        if (StringUtils.isNotBlank(senPgy.getYbbsm())) {
            lqw.eq(SenPgy::getYbbsm, senPgy.getYbbsm());
        }
        if (StringUtils.isNotBlank(senPgy.getXm())) {
            lqw.eq(SenPgy::getXm, senPgy.getXm());
        }
        if (StringUtils.isNotBlank(senPgy.getSex())) {
            lqw.eq(SenPgy::getSex, senPgy.getSex());
        }
        if (StringUtils.isNotBlank(senPgy.getZjlx())) {
            lqw.eq(SenPgy::getZjlx, senPgy.getZjlx());
        }
        if (StringUtils.isNotBlank(senPgy.getZjhm())) {
            lqw.eq(SenPgy::getZjhm, senPgy.getZjhm());
        }
        if (StringUtils.isNotBlank(senPgy.getCsny())) {
            lqw.eq(SenPgy::getCsny, senPgy.getCsny());
        }
        if (StringUtils.isNotBlank(senPgy.getZgxl())) {
            lqw.eq(SenPgy::getZgxl, senPgy.getZgxl());
        }
        if (StringUtils.isNotBlank(senPgy.getPgypxsj())) {
            lqw.eq(SenPgy::getPgypxsj, senPgy.getPgypxsj());
        }
        if (StringUtils.isNotBlank(senPgy.getZgzsbh())) {
            lqw.eq(SenPgy::getZgzsbh, senPgy.getZgzsbh());
        }
        if (StringUtils.isNotBlank(senPgy.getZgzsfzrq())) {
            lqw.eq(SenPgy::getZgzsfzrq, senPgy.getZgzsfzrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZsyxrq())) {
            lqw.eq(SenPgy::getZsyxrq, senPgy.getZsyxrq());
        }
        if (StringUtils.isNotBlank(senPgy.getGznx())) {
            lqw.eq(SenPgy::getGznx, senPgy.getGznx());
        }
        if (StringUtils.isNotBlank(senPgy.getGzdw())) {
            lqw.eq(SenPgy::getGzdw, senPgy.getGzdw());
        }
        if (StringUtils.isNotBlank(senPgy.getSbdw())) {
            lqw.eq(SenPgy::getSbdw, senPgy.getSbdw());
        }
        if (StringUtils.isNotBlank(senPgy.getZyzbh())) {
            lqw.eq(SenPgy::getZyzbh, senPgy.getZyzbh());
        }
        if (StringUtils.isNotBlank(senPgy.getZyzfzrq())) {
            lqw.eq(SenPgy::getZyzfzrq, senPgy.getZyzfzrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZyzzcrq())) {
            lqw.eq(SenPgy::getZyzzcrq, senPgy.getZyzzcrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZyzjzrq())) {
            lqw.eq(SenPgy::getZyzjzrq, senPgy.getZyzjzrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZydd())) {
            lqw.eq(SenPgy::getZydd, senPgy.getZydd());
        }
        if (StringUtils.isNotBlank(senPgy.getYsjb())) {
            lqw.eq(SenPgy::getYsjb, senPgy.getYsjb());
        }
        if (StringUtils.isNotBlank(senPgy.getZyfw())) {
            lqw.eq(SenPgy::getZyfw, senPgy.getZyfw());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzsbh())) {
            lqw.eq(SenPgy::getZyjszgzsbh, senPgy.getZyjszgzsbh());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzsrq())) {
            lqw.eq(SenPgy::getZyjszgzsrq, senPgy.getZyjszgzsrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzsmc())) {
            lqw.eq(SenPgy::getZyjszgzsmc, senPgy.getZyjszgzsmc());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzsjb())) {
            lqw.eq(SenPgy::getZyjszgzsjb, senPgy.getZyjszgzsjb());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzspzrq())) {
            lqw.eq(SenPgy::getZyjszgzspzrq, senPgy.getZyjszgzspzrq());
        }
        if (StringUtils.isNotBlank(senPgy.getZyjszgzspzqf())) {
            lqw.eq(SenPgy::getZyjszgzspzqf, senPgy.getZyjszgzspzqf());
        }
        if (senPgy.getBangding() != null) {
            lqw.eq(SenPgy::getBangding, senPgy.getBangding());
        }
        if (StringUtils.isNotBlank(senPgy.getJuweiId())) {
            lqw.eq(SenPgy::getJuweiId, senPgy.getJuweiId());
        }
        if (senPgy.getDel() != null) {
            lqw.eq(SenPgy::getDel, senPgy.getDel());
        }
        if (senPgy.getAb() != null) {
            lqw.eq(SenPgy::getAb, senPgy.getAb());
        }
        if (senPgy.getIspsy() != null) {
            lqw.eq(SenPgy::getIspsy, senPgy.getIspsy());
        }
        return this.baseMapper.selectAllPgy().stream().filter(a->a.getId()!=null).collect(Collectors.toList()).stream().filter(a->a.getDel()==1).collect(Collectors.toList());
    }

    @Override
    public List<JSONObject> queryList2(SenPgy senPgy) {
        List<JSONObject> senPgies = this.baseMapper.queryList(senPgy);
        if (CollectionUtil.isNotEmpty(senPgies)) {
            List<Long> uid = senPgies.stream().map(a -> a.getLong("uid")).distinct().collect(Collectors.toList()).stream().filter(a -> a != null).collect(Collectors.toList());
            List<Long> jieWei = senPgies.stream().map(a -> {
                String juwei_id = a.getString("juwei_id");
                if (StringUtils.isNotEmpty(juwei_id)) {
                    String[] split = juwei_id.split(",");
                    Long aLong = new Long(split[split.length - 1]);
                    a.put("juwei_id", aLong);
                    return aLong;
                }
                return null;
            }).collect(Collectors.toList()).stream().distinct().filter(a -> a != null).collect(Collectors.toList());
            Map<String, List<JSONObject>> senFormsMapFront = new HashMap<>();
            Map<String, List<JSONObject>> senFormsMapQueen = new HashMap<>();
            List<JSONObject> senFormsListFront = null;
            List<JSONObject> senFormsListQueen = null;
            if (CollectionUtil.isNotEmpty(uid)) {
                senFormsListFront = senFormsMapper.selectByPgrIdFront(uid);
                senFormsListQueen = senFormsMapper.selectByPgrIdQueen(uid);
            }
            if (CollectionUtil.isNotEmpty(senFormsListFront)) {
                for (JSONObject jsonObject : senFormsListFront) {
                    List<JSONObject> jsonObjects = senFormsMapFront.get(jsonObject.getLong("pingid").toString());
                    if (CollectionUtil.isEmpty(jsonObjects)) {
                        jsonObjects = new ArrayList<>();
                    }
                    jsonObjects.add(jsonObject);
                    senFormsMapFront.put(jsonObject.getLong("pingid").toString(), jsonObjects);
                }
            }
            if (CollectionUtil.isNotEmpty(senFormsListQueen)) {
                for (JSONObject jsonObject : senFormsListQueen) {
                    List<JSONObject> jsonObjects = senFormsMapQueen.get(jsonObject.getLong("pingid").toString());
                    if (CollectionUtil.isEmpty(jsonObjects)) {
                        jsonObjects = new ArrayList<>();
                    }
                    jsonObjects.add(jsonObject);
                    senFormsMapQueen.put(jsonObject.getLong("pingid").toString(), jsonObjects);
                }
            }
            List<JSONObject> jsonObjects = null;
            if (CollectionUtil.isNotEmpty(jieWei)) {
                jsonObjects = senStreetsMapper.selectByIds(jieWei);
            }
            Map<Long, List<JSONObject>> jieweiMap = null;
            if (CollectionUtil.isNotEmpty(jsonObjects)) {
                jieweiMap = jsonObjects.stream().collect(Collectors.groupingBy(a -> a.getLong("id")));
            }
            for (JSONObject pgy : senPgies) {
                String nc = pgy.getString("nc");
                if (StringUtils.isNotEmpty(nc)) {
                    pgy.put("nc", new String(Base64.decode(nc)));
                }
                Integer pgnum = 0;//评估书
                Integer cancel = 0;//取消数量
                Integer sls = 0;
                if (CollectionUtil.isNotEmpty(jieweiMap)) {
                    List<JSONObject> value = jieweiMap.get(pgy.getLong("juwei_id"));
                    if (CollectionUtil.isNotEmpty(value)) {
                        pgy.put("jiewei", value.get(0).getString("title"));
                    }
                }
                if (pgy.getLong("uid") != null) {
                    String key = pgy.getLong("uid").toString();
                    if (StringUtils.isEmpty(key)) {
                        pgy.put("sls", sls);
                        pgy.put("pgs", sls);//评估数和受理书一样
                        pgy.put("dpg", pgnum);
                        pgy.put("cdshu", cancel);
                        continue;
                    }
                    if (CollectionUtil.isNotEmpty(senFormsMapFront)) {
                        List<JSONObject> value = senFormsMapFront.get(key);
                        if (CollectionUtil.isNotEmpty(value)) {
                            for (JSONObject jsonObject : senFormsMapFront.get(key)) {
                                Integer status = jsonObject.getInteger("status");
                                if (status == 0) {
                                    pgnum += jsonObject.getInteger("num");
                                } else if (status == 2 || status == 3) {
                                    cancel += jsonObject.getInteger("num");
                                }
                                sls += jsonObject.getInteger("num");
                            }
                        }
                    }
                    if (CollectionUtil.isNotEmpty(senFormsMapQueen)) {
                        List<JSONObject> value = senFormsMapQueen.get(key);
                        if (CollectionUtil.isNotEmpty(value)) {
                            for (JSONObject jsonObject : value) {
                                Integer status = jsonObject.getInteger("status");
                                if (status == 0) {
                                    pgnum += jsonObject.getInteger("num");
                                } else if (status == 2 || status == 3) {
                                    cancel += jsonObject.getInteger("num");
                                }
                                sls += jsonObject.getInteger("num");
                            }
                        }
                    }
                }
                pgy.put("sls", sls);
                pgy.put("pgs", sls);//评估数和受理书一样
                pgy.put("dpg", pgnum);
                pgy.put("cdshu", cancel);
            }
        }
        return senPgies;
    }

    @Override
    public Boolean upload(MultipartFile multipartFile) {
        PgyDataHandle initStockDataHandle = new PgyDataHandle();
        try {
            EasyExcel.read(multipartFile.getInputStream(), SenPgy.class, initStockDataHandle).doReadAll();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (CollectionUtil.isEmpty(initStockDataHandle.getValue())) {
            return Boolean.FALSE;
        }
        List<SenPgy> collect = initStockDataHandle.getValue().stream().filter(a -> StringUtils.isNotEmpty(a.getZjhm()
        )).collect(Collectors.toList());
        if (CollectionUtil.isEmpty(collect)) {
            return Boolean.FALSE;
        }
        ArrayList<SenPgy> collect1 = collect.stream().collect(Collectors
                .collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(SenPgy::getZjhm))),
                        ArrayList::new));
        if (CollectionUtil.isEmpty(collect1)) {
            return Boolean.FALSE;
        }
        for (SenPgy pgy : collect1) {
            pgy.setBangding(1);
            save(pgy);
        }
        Map<String, Long>  map= collect1.stream().collect(Collectors.toMap(SenPgy::getZjhm, SenPgy::getId));
        for (String s : map.keySet()) {
            iSenUserdataService.update(new LambdaUpdateWrapper<SenUserdata>().eq(SenUserdata::getIdno,s).set(SenUserdata::getPgyid,map.get(s)));
        }
        return Boolean.TRUE;
    }

    @SneakyThrows
    @Override
    public void export(HttpServletResponse response) {
        List<JSONObject> senPgies = queryList2(new SenPgy());
        List<SenPgyExcel> collect = senPgies.stream().map(a -> {
            SenPgyExcel senPayExcel = new SenPgyExcel();
            Integer bangding = a.getInteger("bangding");
            Integer psy = a.getInteger("ispsy");
            senPayExcel.setBdzt(bangding == 0 ? "否" : "是");
            senPayExcel.setPsy(psy == 0 ? "否" : "是");
            String jiewei = a.getString("jiewei");
            senPayExcel.setJuwei(jiewei);
            String leibei = a.getString("leibei");
            senPayExcel.setZb(leibei);
            String sex = a.getString("sex");
            senPayExcel.setXb(sex);
            String xm = a.getString("xm");
            senPayExcel.setXm(xm);
            String nc = a.getString("nc");
            senPayExcel.setNc(nc);
            Integer dpg = a.getInteger("dpg");
            senPayExcel.setDpgs(dpg.toString());
            Integer pgs = a.getInteger("pgs");
            senPayExcel.setPgs(pgs.toString());
            Integer sls = a.getInteger("sls");
            senPayExcel.setSls(sls.toString());
            String zslx = a.getString("zslx");
            senPayExcel.setZjlx(zslx);
            return senPayExcel;
        }).collect(Collectors.toList());
        String fileName = URLEncoder.encode("评估员导出" + DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN), "UTF-8").replaceAll("\\+", "%20");
        EasyExcelUtils.writeForWeb(response, fileName, SenPgyExcel.class, collect, "评估员导出");
    }

    @Override
    public void levelExport(HttpServletResponse response) {
        List<JSONObject> senPgies = queryList2(new SenPgy());
        List<JSONObject> senFormsListFront = senFormsMapper.selectAllPgyFront(null);
        List<JSONObject> senFormsListQueen = senFormsMapper.selectAllPgyQueen(null);
        Map<String, List<JSONObject>> senFormsMapFront = new HashMap<>();
        Map<String, List<JSONObject>> senFormsMapQueen = new HashMap<>();
        if (CollectionUtil.isNotEmpty(senFormsListFront)) {
            for (JSONObject jsonObject : senFormsListFront) {
                List<JSONObject> value = senFormsMapFront.get(jsonObject.getLong("pingid").toString());
                if (CollectionUtil.isEmpty(value)) {
                    value = new ArrayList<>();
                }
                value.add(jsonObject);
                senFormsMapFront.put(jsonObject.getLong("pingid").toString(), value);
            }
        }
        if (CollectionUtil.isNotEmpty(senFormsListQueen)) {
            for (JSONObject jsonObject : senFormsListQueen) {
                List<JSONObject> value = senFormsMapQueen.get(jsonObject.getLong("pingid").toString());
                if (CollectionUtil.isEmpty(value)) {
                    value = new ArrayList<>();
                }
                value.add(jsonObject);
                senFormsMapQueen.put(jsonObject.getLong("pingid").toString(), value);
            }
        }
        List<SenPgyLevelExcel> result = new ArrayList<>();
        for (JSONObject senPgy : senPgies) {
            SenPgyLevelExcel senPgyLevelExcel = new SenPgyLevelExcel();
            senPgyLevelExcel.setXm(senPgy.getString("xm"));
            senPgyLevelExcel.setZslx(senPgy.getString("zslx"));
            Integer total = 0;
            if (CollectionUtil.isNotEmpty(senFormsMapFront)&&senPgy.getLong("uid")!=null) {
                List<JSONObject> value = senFormsMapFront.get(senPgy.getLong("uid").toString());
                if (CollectionUtil.isNotEmpty(value)) {
                    for (JSONObject jsonObject : value) {
                        Integer pgdj = jsonObject.getInteger("pgdj");
                        if (pgdj == 0) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setZero(num == null ? 0 : num);
                        }
                        if (pgdj == 1) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setOne(num == null ? 0 : num);
                        }
                        if (pgdj == 2) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setTwo(num == null ? 0 : num);
                        }
                        if (pgdj == 3) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setThree(num == null ? 0 : num);
                        }
                        if (pgdj == 4) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setFour(num == null ? 0 : num);
                        }
                        if (pgdj == 5) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setFive(num == null ? 0 : num);
                        }
                        if (pgdj == 6) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setSix(num == null ? 0 : num);
                        }
                        Integer num = jsonObject.getInteger("num");
                        total += num == null ? 0 : num;
                    }
                }
            }
            if (CollectionUtil.isNotEmpty(senFormsMapQueen) &&senPgy.getLong("uid")!=null) {
                List<JSONObject> value = senFormsMapQueen.get(senPgy.getLong("uid").toString());
                if (CollectionUtil.isNotEmpty(value)) {
                    for (JSONObject jsonObject : value) {
                        Integer pgdj = jsonObject.getInteger("pgdj");
                        if (pgdj == 0) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setZero(num == null ? 0 : senPgyLevelExcel.getZero()+num);
                        }
                        if (pgdj == 1) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setOne(num == null ? 0 : senPgyLevelExcel.getOne()+num);
                        }
                        if (pgdj == 2) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setTwo(num == null ? 0 :  senPgyLevelExcel.getTwo()+num);
                        }
                        if (pgdj == 3) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setThree(num == null ? 0 : senPgyLevelExcel.getThree()+num);
                        }
                        if (pgdj == 4) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setFour(num == null ? 0 : senPgyLevelExcel.getFour()+num);
                        }
                        if (pgdj == 5) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setFive(num == null ? 0 : senPgyLevelExcel.getFive()+num);
                        }
                        if (pgdj == 6) {
                            Integer num = jsonObject.getInteger("num");
                            senPgyLevelExcel.setSix(num == null ? 0 : senPgyLevelExcel.getSix()+num);
                        }
                        Integer num = jsonObject.getInteger("num");
                        total += num == null ? 0 : num;
                    }
                }
            }
            senPgyLevelExcel.setJuwei(senPgy.getString("jiewei"));
            senPgyLevelExcel.setRs(total.toString());
            result.add(senPgyLevelExcel);
        }
        String fileName = null;
        try {
            fileName = URLEncoder.encode("评估员导出" + DateUtil.format(new Date(), DatePattern.PURE_DATE_PATTERN), "UTF-8").replaceAll("\\+", "%20");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        try {
            EasyExcelUtils.writeForWeb(response, fileName, SenPgyLevelExcel.class, result, "评估员导出");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public SenPgyRankStatisticsVo rankStatistics(Long id) {
        if (id == null || id == 0){
            return  new SenPgyRankStatisticsVo();
        }

        SenPgyRankStatisticsVo senPgyRankStatisticsVo = new SenPgyRankStatisticsVo();
        Integer total = 0;
        Integer one = 0;
        Integer two = 0;
        Integer three = 0;
        Integer four = 0;
        List<JSONObject> senFormsListFront = senFormsMapper.selectAllPgyFront(id);
        List<JSONObject> senFormsListQueen = senFormsMapper.selectAllPgyQueen(id);
        if (CollectionUtil.isEmpty(senFormsListQueen) &&CollectionUtil.isEmpty(senFormsListFront)){
            return  new SenPgyRankStatisticsVo(0.0,0.0,0.0,0.0);
        }
        if (CollectionUtil.isNotEmpty(senFormsListFront)){
            for (JSONObject jsonObject : senFormsListFront) {
                    Integer pgdj = jsonObject.getInteger("pgdj");
                    if (pgdj == 0||pgdj == 1) {
                        Integer num = jsonObject.getInteger("num");
                        one= num == null ? 0 : num;
                    }
                    if (pgdj == 2||pgdj == 3) {
                        Integer num = jsonObject.getInteger("num");
                        two  = num == null ? 0 : num;
                    }
                    if (pgdj == 4) {
                        Integer num = jsonObject.getInteger("num");
                        three  = num == null ? 0 : num;
                    }
                    if (pgdj == 5 || pgdj == 6) {
                        Integer num = jsonObject.getInteger("num");
                        four  = num == null ? 0 : num;
                    }
                    Integer num = jsonObject.getInteger("num");
                    total += num == null ? 0 : num;
                }

        }
        if (CollectionUtil.isNotEmpty(senFormsListQueen)){
            for (JSONObject jsonObject : senFormsListQueen) {
                Integer pgdj = jsonObject.getInteger("pgdj");
                if (pgdj == 0||pgdj == 1) {
                    Integer num = jsonObject.getInteger("num");
                    one+= num == null ? 0 : num;
                }
                if (pgdj == 2||pgdj == 3) {
                    Integer num = jsonObject.getInteger("num");
                    two+= num == null ? 0 : num;
                }
                if (pgdj == 4) {
                    Integer num = jsonObject.getInteger("num");
                    three += num == null ? 0 : num;
                }
                if (pgdj == 5 || pgdj == 6) {
                    Integer num = jsonObject.getInteger("num");
                    four  += num == null ? 0 : num;
                }
                Integer num = jsonObject.getInteger("num");
                total += num == null ? 0 : num;
            }

        }
        DecimalFormat format = new DecimalFormat("#.00");
        senPgyRankStatisticsVo.setOne(new Double(format.format(one*1.0/(total*1.0)*100)));
        senPgyRankStatisticsVo.setTwo(new Double(format.format(two*1.0/(total*1.0)*100)));
        senPgyRankStatisticsVo.setThree(new Double(format.format(three*1.0/(total*1.0)*100)));
        senPgyRankStatisticsVo.setFour(new Double(format.format(four*1.0/(total*1.0)*100)));
        return senPgyRankStatisticsVo;
    }

    @Override
    public List<UpdateUserJuWeiDTO> selectJuWei(List<String> asList) {
        return this.baseMapper.selectJuWei(asList);
    }
}